const http = require('http');
const fs = require('fs');
const url = require('url')

let server = http.createServer((req, res) => {
  console.log(req.url);
  let obj = url.parse(req.url, true)

  console.log(obj);

  fs.readFile(`www${req.url}`, (err, data) => {
    if (err) {
      res.writeHeader('404')
      // res.write('Not Found')
      fs.readFile('www/404.html', (err2, data2) => {
        if (err2) {
          res.write('Not Found')
        } else {
          res.write(data2)
        }
        res.end()
      })
    } else {
      res.write(data)
      res.end()

    }



  })


})

server.listen(1230)